<template>
	<view>
		<view class="friendInfo"  v-for="(item,index) in friendList">
			<view class="info">
				<image :src="item.belongUserInfo.avatar" class="avatar"></image>
				<text>{{item.belongUserInfo.userName}}</text>
			</view>
			<view class="button-box">
				<button @click="aduit(1,item.id)">接受</button>
				<button @click="aduit(2,item.id)">拒绝</button>
			</view>
		</view>
	</view>
</template>

<script>
import { auditFriend, getFriendsList } from '../../api/contacts'
	export default {
		data() {
			return {
				friendList:[],
				userInfo:''
			}
		},
		onLoad() {
			this.userInfo=uni.getStorageSync('userInfo')
			console.log("ss:",this.userInfo.userId);
			const params={
				'userId':this.userInfo.userId,
				'status':0
			}

			// 获取好友列表
			getFriendsList(params).then(res=>{
				if(res.code===200){
					this.friendList=res.rows
					console.log('friendList:',this.friendList)
				}
			})


		},


		methods: {
			// 审核
			aduit(staue,id){
				let belongUser = this.friendList.find(item=>item.id===id);
				const params={
					  "black": 0,
					  "belongUserId": belongUser.belongUserId,
					  "createUserId": this.userInfo.userId,
					  "groupId": 0,
					  "special": 0,
					  "id": id,
					  "status": staue,
					  "userId": this.userInfo.userId
				}
				auditFriend(params).then(res=>{
					if(res.code===200){
						uni.showToast({
							title:'添加成功',
							icon:'success'
						})

					}
				})
			}

		}
	}
</script>

<style lang="scss">
				.friendInfo{
					display: flex;
					align-items: center;
					padding: 20upx;
					justify-content: space-between;
					background-color: $bg-color;

					.info{
						display: flex;
						align-items: center;

						text{
							color: white;
						}
					}

					.avatar{
						width: 100upx;
						height: 100upx;
						border-radius: 50%;
						border: 1px white solid;
						margin-right: 20upx;
					}

					.button-box{
						display: flex;

						button{
							margin-left: 10upx;
						}
					}

				}
</style>
